<?php
class Pagemanager_Model_Pagedecision implements Pagemanager_Model_Mainable{
    
    private $action_handler;
    
    private $page = array();
    
    private $get_statuses_data;
    private $get_access_level_data;
    private $get_image_data;
    private $get_subcategory_data;
    private $core_controller_csrftoken;
    
    private $pagemanager_data_selectcurrentpagedata;
    
    public function main(array $variables = null) {
        switch ($variables['get']['page']){
            case 'dodaj-strone':
                return $this->add_new_page($variables);
                break;
            case 'wstaw-strone':
                return $this->insert_new_page($variables);
                break;
            case 'edytuj-strone':
                return $this->edit_current_page($variables);
                break;
            case 'aktualizuj-strone':
                return $this->update_current_page($variables);
                break;
            case 'usun-strone':
                return $this->delete_current_page($variables);
                break;
            default:
                return $this->default_action($variables);
                break;
        }
    }
    
    private function delete_current_page(array $variables = null){
        $this->action_handler = new Pagemanager_Model_Deletepage;
        return $this->action_handler->main($variables);
    }
    
    private function update_current_page(array $variables = null){
        $this->action_handler = new Pagemanager_Model_Updatepagedata;
        return $this->action_handler->main($variables);
    }
    
    private function edit_current_page(array $variables = null){
        $this->get_other_data($variables);
        $this->pagemanager_data_selectcurrentpagedata = new Pagemanager_Data_Selectcurrentpagedata;
        $this->page['content'] = $this->pagemanager_data_selectcurrentpagedata->main($variables);
        return $this->page;
    }
    
    private function insert_new_page(array $variables = null){
        $this->action_handler = new Pagemanager_Model_Insertpage;
        return $this->action_handler->main($variables);
    }
    
    private function add_new_page(array $variables = null){
        return $this->get_other_data($variables);
    }
    
    private function default_action(array $variables = null){
        unset($variables);
        $this->action_handler = new Pagemanager_Model_Pagemanager;
        return $this->action_handler->main($variables);
    }
    
    private function get_other_data(array $variables = null){
    
        $this->core_controller_csrftoken = new Core_Controller_Csrftoken;
        $this->get_access_level_data = new Privileges_Data_Getpriviligeslist;
        $this->get_image_data = new Modulemanager_Data_Selectimage;
        $this->get_statuses_data = new Accountsstatus_Data_Getaccountsstatus;
        $this->get_subcategory_data = new Pagemanager_Data_Getallsubcategories;
        
        $this->page['template'] = WEB_ROOT_FOLDER."pagemanager/views/add.php";
        $this->page['csrf_token'] = $this->core_controller_csrftoken->main($variables);
        $this->page['access_level'] = $this->get_access_level_data->main($variables);
        $this->page['images'] = $this->get_image_data->main($variables);
        $this->page['status_name'] = $this->get_statuses_data->main($variables);
        $this->page['subcategory'] = $this->get_subcategory_data->main($variables);
        return $this->page;
        
    }

}
